﻿using System;
using WebUI.BL.Email;
using WebUI.DAL;

namespace WebUI
{
    public partial class GetCode : System.Web.UI.Page
    {
        private string MODE = "";
        private string rtn = "";

        private string emailinput = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            GetRequestData();
            WriteResponse();
        }

        private void GetRequestData()
        {
            if (Request.Form["MODE"] != null)
            {
                this.MODE = Request.Form["MODE"].ToString();
            }
            if (Request.Form["emailinput"] != null)
            {
                this.emailinput = Request.Form["emailinput"].ToString();
            }
        }

        private void WriteResponse()
        {
            if (MODE == "1")
            {
                tbl_Email emailitem = new tbl_Email();
                emailitem.Email = emailinput;
                emailitem.RegisterDate = DateTime.Now;
                emailitem.Status = "NORMAL";

                EmailBL email = new EmailBL();
                email.clsEmailInsert(emailitem);

                rtn += "[[";
                rtn += "\"" + "1" + "\"";
                rtn += "]]";
            }

            Response.ContentType = "text/plain";
            Response.Write(rtn);
        }
    }
}